package com.qfhd.soft.cjzcore.Moudle;

import com.qfhd.soft.cjzcore.Core.CJLogger;
import com.qfhd.soft.cjzcore.Model.Task_image_detail_model;
import com.qfhd.soft.cjzcore.Model.Task_image_item_model;
import com.qfhd.soft.cjzcore.Model.Task_try_model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class CJImgTaskHelper {
    private List<Task_image_item_model> imgTask_list = new ArrayList<>();
    private Task_image_detail_model detialModel = new Task_image_detail_model();

    private static CJImgTaskHelper imgTaskHelper;
    public static CJImgTaskHelper getInstance(){
        if(imgTaskHelper == null){
            synchronized (CJImgTaskHelper.class){
                imgTaskHelper = new CJImgTaskHelper();
            }
        }
        return imgTaskHelper;
    }

    public void setImgTaskList(JSONArray jsonArray) {
        imgTask_list.clear();
        for (int i=0; i<jsonArray.length(); i++){
            try {
                JSONObject obj = jsonArray.getJSONObject(i);
                Task_image_item_model tmp = Task_image_item_model.getModelByJSONObject(obj);
                imgTask_list.add(tmp);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        CJLogger.v("imgTask_list size:" + imgTask_list.size());
    }

    public void changeToDetailModel(JSONObject obj){
        detialModel = Task_image_detail_model.getModelByJSONObject(obj);
    }

    public Task_image_detail_model getDetailModel(){
        return detialModel;
    }

    public List<Task_image_item_model> getImgTask_list(){
        return imgTask_list;
    }

    public String getTid(int position){
        Task_image_item_model model = imgTask_list.get(position);
        return model.id;
    }
}
